package pl.prv.polanie.client.dto;

import java.util.Comparator;

import com.google.gwt.user.client.rpc.IsSerializable;


public class CSVAcademicTitleDTO extends Object implements IsSerializable, ICSVDTO {
	
    public static final int SORT_CONST__TITLE = 0;
    public static final int SORT_CONST__ID = 1;

    
    
	private long id;
	private String title;

	
    private boolean highlighted;

	
	public CSVAcademicTitleDTO() {}
	
	public CSVAcademicTitleDTO(long id, String title) {
		this.id = id;
		this.title = title;
	}

	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	
	public String toString() {
		String result = "" +
			"[ " + CSVAcademicTitleDTO.class + "]" +
			"title: " + title; 
		return result;
	}
	
	public String toLabel() {
		String result = "" +
			title;
		return result;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public boolean isHighlighted() {
		return highlighted;
	}

	public void setHighlighted(boolean highlighted) {
		this.highlighted = highlighted;
	}
	
	
	
	
	
	public String getField(int col) {
		if (col == SORT_CONST__ID) {
			return "" + getId();
		} else if (col == SORT_CONST__TITLE) {
			return "" + getTitle();
		}
		return "no field";
	}


	@SuppressWarnings("unchecked")
	public static Comparator getComparator(final int colIndex) {
		Comparator cmp = new Comparator() {
			public int compare(Object o1, Object o2) {

//			    final int BEFORE = -1;
			    final int EQUAL = 0;
//			    final int AFTER = 1;
			    
			    CSVAcademicTitleDTO obj1;
			    CSVAcademicTitleDTO obj2;
			    if (o1 instanceof CSVAcademicTitleDTO && o2 instanceof CSVAcademicTitleDTO) {

					obj1 = (CSVAcademicTitleDTO) o1;
					obj2 = (CSVAcademicTitleDTO) o2;
					
					//this optimization is usually worthwhile, and can
					//always be added
					if ( obj1 == obj2 ) return EQUAL;

					//primitive numbers follow this form
					if (colIndex == SORT_CONST__ID) {
						Long l1 = new Long(obj1.getId());
						Long l2 = new Long(obj2.getId());
						return l1.compareTo(l2);
					} else if (colIndex == SORT_CONST__TITLE) {
						return obj1.getTitle().compareTo(obj2.getTitle());
					}
					
				};
				return EQUAL;
			}
		};

		return cmp;
	}
	

}
